var express = require('express');
var multer = require('multer');

var app = express();
app.all('*', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    next();
});


var upload = multer({
    dest: 'upload/'
});

// 单图上传
//multer有single()中的名称必须是表单上传字段的name名称。
app.post('/upload', upload.single('logo'), function(req, res, next) {
    
    var file = req.file;
    console.log('文件类型：%s', file.mimetype);
    console.log('原始文件名：%s', file.originalname);
    console.log('文件大小：%s', file.size);
    console.log('文件保存路径：%s', file.path);

    res.jsonp({
        status:'200 ok',
        data:{
            a:222
        }
    });
});

app.get('/form', function(req, res, next) {
    var form = fs.readFileSync('./form.html', {
        encoding: 'utf8'
    });
    res.send(form);
});

app.listen(3000);